feat: Add CacheTagService to @cacheable/utils#1646
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the CacheTagService utility, which provides tag-based cache invalidation on top of any Keyv store using a lazy invalidation model. The feedback highlights opportunities to parallelize sequential asynchronous operations using Promise.all in setKeyTags, isKeyFresh, and invalidateTags to prevent performance bottlenecks when handling multiple tags.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the CacheTagService to provide tag-based invalidation on top of any Keyv store using a lazy invalidation model. The feedback suggests defensive checks in getTagVersions to ensure compatibility with older or custom Keyv stores that might not return an array. Additionally, it recommends deduplicating the input tags in both setKeyTags and invalidateTags to prevent redundant store queries and duplicate writes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1646 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 27 +1
Lines 2747 2820 +73
Branches 613 622 +9
=========================================
+ Hits 2747 2820 +73 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Please check if the PR fulfills these requirements
What kind of change does this PR introduce?
As suggested in #1640, this PR implements
CacheTagServicein the@cacheable/utilspackage. It is a standalone service that adds tag-based invalidation on top of any Keyv store, without touching adapters or thecacheablecore.The invalidation model is lazy, in the spirit of Symfony's tag-aware cache and Next.js's
revalidateTag:invalidateTagit bumps a per-tag version counter rather than scanning and deleting keys.isKeyFreshcompares each key's stored tag snapshot to current versions. That keeps invalidation constant-time at the cost of one extra read per cache lookup.Integration into
cacheableandcache-managerare intentionally left for follow-ups so this PR stays focused on the primitive. Optimisations per-store type (like an atomic Redis fast path using Lua) are also natural follow ups.